import React, { Component } from 'react'
import { Carousel } from 'antd-mobile';
import { get } from 'api/http'
export default class Swiper extends Component {
    state = {
        data: [],
    }

    async getSwiper() {
        let rs = await get('/api/swiper');
        // console.log(rs);
        this.setState({
            data:rs.data.datalist
        })
    }

    componentDidMount() {
        // 调用数据
        this.getSwiper();
    }
    render() {
        return (
            <Carousel
                autoplay={true}
                infinite={true}
            >
                {this.state.data.map((val,index) => (
                        <img key={index}
                            src={val.img}
                            alt={index}
                            style={{ width: '100%', verticalAlign: 'top' }}
                            onLoad={() => {
                                this.setState({ imgHeight: 'auto' });
                            }}
                        />
                ))}
            </Carousel>
        )
    }
}
